package com.dc.entity;


import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Objects;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "t_calibration_ship_weld")
public class CalibrationShipWeldEntity {

    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    @JsonIgnore
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "ship_id", columnDefinition = "bigint unsigned NOT NULL")
    private ShipEntity ship;

    @Transient
    private Long shipId;

    @Transient
    private String shipName;

    @Column(name = "length")
    public Double length;  // 焊接长度(m)

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "date")
    public Date date;      // 工作时间

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "start_time")
    public Date startTime;     // 工作开始时间

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "end_time")
    public Date endTime;       // 工作结束时间

    @Column(name = "machine_num")
    public Integer machineNum; // 焊机数量

    @Column(name = "start_co2")
    public Double startCO2;    // CO2开始读数

    @Column(name = "end_co2")
    public Double endCO2;      // CO2结束读数

    // endCO2 - startCO2
    @Column(name = "co2")
    public Double co2;         // CO2量     // 动态计算

    // gas/length
    @Column(name = "co2_by_unit")
    public Double co2ByUnit;   // 单位用CO2量(m³/m)   // 动态计算

    @Column(name = "powers")
    public Double powers;     // 耗电能(kwh)   动态计算

    @Column(name = "power_by_unit")
    public Double powerByUnit;       // 单位耗电(KWh/m)  动态计算

    @Column(name = "updater")
    private String updater;

    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @Column(name = "update_time")
    private Date updateTime = new Date();

    @JsonIgnoreProperties(value = { "calibrationShipWeldEntity" })
    @OneToMany(cascade={CascadeType.PERSIST, CascadeType.MERGE, CascadeType.REMOVE, CascadeType.REFRESH}, fetch = FetchType.EAGER)
    @JoinColumn(name = "calibration_ship_weld_id", referencedColumnName = "id")
    private List<CalibrationShipWeldChildEntity> inner = new ArrayList<>();

    @Override
    public String toString() {
        return "CalibrationShipWeldEntity{" +
                "id=" + id +
                ", ship=" + ship +
                ", shipId=" + shipId +
                ", shipName='" + shipName + '\'' +
                ", length=" + length +
                ", startTime=" + startTime +
                ", endTime=" + endTime +
                ", machineNum=" + machineNum +
                ", startCO2=" + startCO2 +
                ", endCO2=" + endCO2 +
                ", co2=" + co2 +
                ", co2ByUnit=" + co2ByUnit +
                ", powers=" + powers +
                ", powerByUnit=" + powerByUnit +
                ", updater='" + updater + '\'' +
                ", updateTime=" + updateTime +
                ", inner=" + inner.size() +
                '}';
    }

}
